package com.tencent.wuyanzu.whattoeat;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.tencent.wuyanzu.whattoeat.Global.ARGS;

public class SplashActivity extends Activity {
    private final int SPLASH_DISPLAY_TIME = 3000;

    private final String TAG="SplashActivity";
    SharedPreferences msharePreference;
    SharedPreferences.Editor msharePreferenceEd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        msharePreference=getSharedPreferences("whattoeat",Activity.MODE_PRIVATE);
        msharePreferenceEd=msharePreference.edit();
        setContentView(R.layout.activity_splash);

        Boolean isFirst=msharePreference.getBoolean("isFirst",true);
        if(isFirst)
        {
            msharePreferenceEd.putBoolean("isFirst",false);
            msharePreferenceEd.commit();
            Log.i(TAG,""+msharePreference.getBoolean("isFirst",false));
            Log.i(TAG,""+msharePreference.getBoolean("isFirst",true));
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent mainIntent = new Intent(SplashActivity.this,InitFlavourActivity.class);
                    SplashActivity.this.startActivity(mainIntent);
                    SplashActivity.this.finish();
                }
            }, SPLASH_DISPLAY_TIME);
        }
        else
        {
            ARGS.UID=msharePreference.getInt("uid",-1);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
                    SplashActivity.this.startActivity(mainIntent);
                    SplashActivity.this.finish();
                }
            }, SPLASH_DISPLAY_TIME);
        }



    }
}
